// pages/adverseEvent/adverseEvent.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dtype:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.d.ceshiUrl + '/Api/Event/index',
      method: "post",
      data: {
        uid: app.d.userId,
        
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          that.setData({
            list: res.data.list,
            dtype: 1
          });
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },
  goto:function (e) {
    if(this.data.dtype==1){
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url:"../redactEvent/redactEvent?id=" + id
      })
    }
   
  },

  del:function (e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    that.setData({
      dtype:0
    });
    wx.request({
      url: app.d.ceshiUrl + '/Api/Event/del',
      method: "post",
      data: {
        id:id,
        uid:app.d.userId
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          wx.showToast({
            title: res.data.err,
            duration:2000
          });
          that.setData({
            dtype:1
          });
          that.onShow();
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})